/**
  ******************************************************************************
  * @file    bsp_nand_ex.h
  * @author  Iron
  * @date    2018-07-09
  * @version v1.0
  * @brief   bsp_nand_ex header file
  */

#ifndef __BSP_NAND_EX_H
#define __BSP_NAND_EX_H

#ifdef __cplusplus
extern "C" {
#endif

/* includes ------------------------------------------------------------------*/
#include <stdint.h>

/* exported types ------------------------------------------------------------*/
typedef struct
{
    uint32_t page_size;
    uint32_t pages_per_block;
    uint32_t spare_size;
    uint32_t spare_free;
    uint32_t spare_block_status_offs;
    uint32_t block_start;
    uint32_t block_end;
    uint32_t block_total;
//  uint32_t plane_num;
} bsp_nand_partition_t;

/* exported constants --------------------------------------------------------*/
extern const bsp_nand_partition_t nand_par_default;
//extern const bsp_nand_partition_t nand_par_hd_data;
//extern const bsp_nand_partition_t nand_par_log;
//extern const bsp_nand_partition_t nand_par_file;

/* exported macro ------------------------------------------------------------*/
#define BSP_NAND_EX_FAIL                0
#define BSP_NAND_EX_OK                  1

/* exported functions ------------------------------------------------------- */
int32_t bsp_nand_flash_read(const bsp_nand_partition_t *partition, uint32_t addr, uint8_t *data, uint32_t data_len);
int32_t bsp_nand_flash_write(const bsp_nand_partition_t *partition, uint32_t addr, const uint8_t *data, uint32_t data_len);

int32_t bsp_nand_flash_erase_block(const bsp_nand_partition_t *hnand, uint32_t addr);

int32_t bsp_nand_flash_read_page(const bsp_nand_partition_t *partition, uint32_t page,
                                 uint8_t *data,  uint32_t data_len, uint8_t *spare, uint32_t spare_len);

int32_t bsp_nand_flash_write_page(const bsp_nand_partition_t *partition, uint32_t page,
                                  const uint8_t *data,  uint32_t data_len, const uint8_t *spare, uint32_t spare_len);
/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __BSP_NAND_EX_H */

/******************* (C)COPYRIGHT 2018 ***** END OF FILE *********************/
